<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>callback</title>
	</head>
	<body>
		<script type="text/javascript">
			function fac(n,callback) {
				var s=1;
				for(var i=1;i<=n;i++){
					s=s*i;
				}
				callback(s);
			}
			/*function out(s){
				alert("阶乘为"+s)
			}
			fac(5,out);*/
			fac(5,function (a) {
				alert("阶乘为"+a);
			});
			fac(10,function (x) {
				console.log("==>",x);
			});
		</script>
	</body>
</html>
